function RefreshPostForm() {
  document.getElementById("link_url").disabled = true;
  document.getElementById("description").disabled = true;
  document.getElementById("image").disabled = true;
  document.getElementById("video_url").disabled = true;
  document.getElementById("post_button").disabled = true;
  document.getElementById("preview_button").disabled = true;
  
  if (document.getElementById("link_radio").checked) {
    document.getElementById("link_url").disabled = false;
    document.getElementById("description").disabled = false;
    document.getElementById("post_button").disabled = false;
    document.getElementById("preview_button").disabled = false;
  }
  if (document.getElementById("image_radio").checked) {
    document.getElementById("image").disabled = false;
    document.getElementById("post_button").disabled = false;
    document.getElementById("preview_button").disabled = false;
  }
  if (document.getElementById("video_radio").checked) {
    document.getElementById("video_url").disabled = false;
    document.getElementById("post_button").disabled = false;
    document.getElementById("preview_button").disabled = false;
  }
}

function YoutubeParse(url){
  var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#\&\?]*).*/;
  var match = url.match(regExp);
  if (match && match[7].length == 11) {
    return match[7];
  } else {
    return "NO";
  }
}

function YoutubeVideoChange() {
  document.getElementById("video_url_parsed").value =
    YoutubeParse(document.getElementById("video_url").value);
}

function Preview() {
  var text = "No Preview Available";
  if (document.getElementById("video_radio").checked) {
    // Make into youtube
    // text = "bokep";
    url = document.getElementById("video_url").value;
    id = YoutubeParse(url);
    if (id == "NO") {
      text = "Youtube Link is wrong";
    } else {
      text = "<iframe class='youtube-player' type='text/html' width='640' height='385' src='" +
             "http://www.youtube.com/embed/" + id + "' frameborder='0'></iframe>";
    }
  } else if (document.getElementById("link_radio").checked) {
    url = document.getElementById("link_url").value;
    text = "<ul>";
    text += "<li>";
    text += "<a href='" + url + "'>" + url + "</a>";
    text += "</li>";
    text += "<li>";
    text += document.getElementById("description").value;
    text += "</li>";
    text += "</ul>";
  }
  
  document.getElementById("content_list").innerHTML =
    "<li class=odd_content>" + text + "</li>";
}
